//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.come.control;

import com.tool.image.ImageMixDeal;
import com.tool.image.ManimgAttribute;
import org.come.Jpanel.FrameMessageChangeJpanel;
import org.come.Jpanel.GameJpanel;
import org.come.action.FromServerAction;
import org.come.bean.NChatBean;
import org.come.until.GsonUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NChatControl implements FromServerAction {
    public NChatControl() {
    }

    @Override
    public void controlMessFromServer(String mes, String type) {
        NChatBean nChatBean = GsonUtil.getGsonUtil().getgson().fromJson(mes, NChatBean.class);
        if (nChatBean.getId() != 0 && nChatBean.getId() != 1) {
            if (nChatBean.getId() == 8 || nChatBean.getId() == 9) {
                GameJpanel.getGameJpanel().addBox(nChatBean.getMessage(), nChatBean.getId(), nChatBean.getSkin());
                return;
            }
            if (nChatBean.getId() == 10) {
                GameJpanel.getGameJpanel().addBoos(nChatBean.getMessage(), nChatBean.getId(), nChatBean.getSkin());
                return;
            }
        } else {

            String extractedText = extractText(nChatBean.getMessage());
            if (extractedText != null) {
                ManimgAttribute attribute = ImageMixDeal.huoquLogin(extractedText);


                if (attribute != null) {
                    attribute.Dialogue1(nChatBean.getMessage(), null, null, null, 0);
                }
            } else {
                ManimgAttribute attribute = ImageMixDeal.huoquLogin(nChatBean.getRole());


                if (attribute != null) {

                    if (nChatBean.getGoodNum() != null)

                        attribute.Dialogue1(nChatBean.getMessage(), nChatBean.getRole(), nChatBean.getRoleId(), nChatBean.getGoodNum(), nChatBean.getGoodNumType());
                    else
                        attribute.Dialogue1(nChatBean.getMessage(), nChatBean.getRole(), nChatBean.getRoleId(), null, 0);
                }
            }


        }

        FrameMessageChangeJpanel.addtext(nChatBean.getId(), nChatBean.getMessage(), nChatBean.getRoleId(), nChatBean.getRole(),nChatBean.getGoodNum(),nChatBean.getGoodNumType());
    }


    private String extractText(String message) {
        // 使用正则表达式提取“汪了个汪”
        Pattern pattern = Pattern.compile("name\":\"\\[(.*?)\\]\"");
        Matcher matcher = pattern.matcher(message);
        if (matcher.find()) {
            return matcher.group(1);
        }
        return null;
    }
}
